package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.GrammarSymbol;
import ar.edu.caece.compiler.grammar.ParsingException;
import ar.edu.caece.compiler.grammar.TokenVisitorInterface;
import ar.edu.caece.compiler.grammar.nonterminals.TEXTOA;
import ar.edu.caece.compiler.grammar.nonterminals.TEXTO1;
import ar.edu.caece.compiler.grammar.terminals.GrammarTerminal;
import ar.edu.caece.compiler.grammar.terminals.CadenaToken;

public class TEXTO1Factory extends AbstractTokenVisitorFactory {

	private static TEXTO1Factory INSTANCE;
	
	private TEXTOAFactory textoaFactory;
	private TokenVisitorInterface parseTEXTOA;
	
	public static TEXTO1Factory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new TEXTO1Factory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			textoaFactory = TEXTOAFactory.getInstance();
			parseTEXTOA = textoaFactory.makeVisitor();
		}
	};
	
	private TEXTO1Factory() throws Exception {

	}
	
	@Override
	public TokenVisitorInterface makeChainedVisitor(
			final TokenVisitorInterface siguiente) throws Exception {
		initializer.init();

		return new CadenaToken.CadenaChainVisitor(siguiente) {
			
			@Override
			public GrammarSymbol cadenaCase(CadenaToken llamador) throws Exception {
				return new TEXTO1(llamador, (TEXTOA) nextToken().execute(parseTEXTOA));
			}
		};
	
	}
	@Override
	public TokenVisitorInterface makeVisitor() throws Exception {
		initializer.init();

		return new CadenaToken.CadenaTokenVisitor() {
			
			@Override
			public GrammarSymbol defaultCase(GrammarTerminal llamador) throws Exception {
				throw new ParsingException("Error de parsing.",TEXTO1.class,llamador);
			}
			
			@Override
			public GrammarSymbol cadenaCase(CadenaToken llamador) throws Exception {
				return new TEXTO1(llamador, (TEXTOA) nextToken().execute(parseTEXTOA));
			}
		};
	}
	
	
}
